package com.itheima_04;

public class StringBuilderDemo {
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder();
        System.out.println("sb: " + sb);
        System.out.println(sb.length()); // 0

        StringBuilder sb2 = new StringBuilder("hello");
        System.out.println("sb2: " + sb2);
        System.out.println(sb2.length());

        // 创建对象
        StringBuilder sb3 = new StringBuilder();
        StringBuilder sb4 = sb3.append("hello");
        System.out.println("sb3: " + sb3);
        System.out.println("sb4: " + sb4);

        StringBuilder sb5 = new StringBuilder();
        sb5.append("hello").append(" world");
        System.out.println("sb5: " + sb5);
        sb5.reverse();
        System.out.println("sb5: " + sb5);

        // StringBuilder和String相互转换
        StringBuilder sb6 = new StringBuilder("hello");
        sb6.append("java");
        System.out.println(sb6.toString());

    }
}

// String: 内容是不可变的
// StringBuilder: 内容是可变的
